<template>
  <div class="app-container app-containerMoneytabel">
    <div class="filter-container">
      <el-select style="marginRight:15px;" size="small" v-model="listQuery.defKey" placeholder="请选择业务类型">
        <el-option
          v-for="item in defKeyOptions"
          :key="item.value"
          :label="item.label"
          :value="item.value">
        </el-option>
      </el-select>
      <el-date-picker
        size="small" style="marginRight:15px;"
        v-model="listQuery.queryTime"
        type="daterange"
        range-separator="-"
        start-placeholder="开始日期"
        end-placeholder="结束日期">
      </el-date-picker>
      <el-input size="small" @keyup.enter.native="handleFilter" placeholder="请输入姓名" style="width: 150px;marginRight:15px;" class="filter-item"
        v-model="listQuery.userSearchStr">
      </el-input>
      <el-input size="small" @keyup.enter.native="handleFilter" placeholder="请输入身份证号" style="width: 200px;" class="filter-item"
        v-model="listQuery.idCardSearchStr">
      </el-input>
      <el-button size="small" class="filter-item filter-itemBut" type="primary" icon="el-icon-search" @click="handleFilter">搜索</el-button>
    </div>
    <el-table class="filter-list" :data="list" v-loading="listLoading" element-loading-text="Loading" border fit
      highlight-current-row>
      <el-table-column type="index" width="50" label="序号"></el-table-column>
      <el-table-column label="申请人名称" align="center">
        <template slot-scope="scope">
          {{scope.row.approvalUserName}}
        </template>
      </el-table-column>
      <el-table-column label="身份证号" align="center">
        <template slot-scope="scope">
          <el-tooltip class="item" effect="dark" :content="scope.row.idCard" placement="top-start">
            <p>{{scope.row.idCard | idCardFun}}</p>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column label="业务类型" align="center">
        <template slot-scope="scope">
          {{ scope.row.approvalDefKey | mapLabel('approvalKey')}}
        </template>
      </el-table-column>
      <el-table-column label="当前环节" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.taskName">{{scope.row.taskName}}</span>
          <span v-else>已结办</span>
        </template>
      </el-table-column>
      <el-table-column label="申请时间" align="center">
        <template slot-scope="scope">
          <i class="el-icon-time"></i>
          <span v-if="scope.row.approvalPostTime">{{scope.row.approvalPostTime | parseTime('{y}-{m}-{d} {h}:{i}')}}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作" width="250" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button type="primary" v-if="pageKey===pageKeyMap.wait" size="mini" @click="handleAudit(scope.row)">立即受理</el-button>
          <el-button type="primary" v-else-if="pageKey===pageKeyMap.joined" size="mini" @click="handleProgressView(scope.row)">查看详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="pagination-container">
      <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="listQuery.page"
        :page-sizes="[10,20,30, 50]" :page-size="listQuery.size" layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </div>
  </div>
</template>
<script>
import { queryPage } from "@/api/approval";
import permission from "@/directive/permission/index.js"; // 权限判断指令

export default {
  directives: { permission },
  data() {
    return {
      list: null,
      total: 0,
      listLoading: true,
      username: "",
      listQuery: {
        url: this.pageKey,
        page: 1,
        size: 10,
        startTime: null,
        endTime: null,
        defKey: null,
        queryTime: [],
        userSearchStr: null,
        idCardSearchStr: null,
        sort: "+id"
      },
      pageKeyMap: {
        wait: "wait",
        joined: "joined"
      },
      textMap: {
        update: "更新",
        create: "添加"
      },
      defKeyOptions: this.$store.state.dict.options["approvalKey"]
    };
  },
  mounted: function() {
    this.fetchData();
  },
  props: ["pageKey"],
  methods: {
    fetchData() {
      this.listLoading = true;
      queryPage(this.listQuery).then(response => {
        this.list = response.data.records;
        this.total = response.data.total;
        this.listLoading = false;
      });
      this.listLoading = false;
    },
    handleFilter() {
      if (this.listQuery.queryTime.length > 1) {
        this.listQuery.startTime = this.listQuery.queryTime[0].getTime() / 1000;
        this.listQuery.endTime = this.listQuery.queryTime[1].getTime() / 1000;
      }
      this.listQuery.page = 1;
      this.fetchData();
    },
    handleSizeChange(val) {
      this.listQuery.size = val;
      this.fetchData();
    },
    handleCurrentChange(val) {
      this.listQuery.page = val;
      this.fetchData();
    },
    handleCheckedResources(keys) {
      this.temp.resourcesIds = keys;
    },
    handleAudit(row) {
      this.$router.push({
        name: "acceptAudit",
        query: {
          action: "audit",
          id: row.approvalId,
          taskId: row.taskId,
          approvalKey: row.approvalDefKey
        }
      });
    },
    handleProgressView(row) {
      this.$router.push({
        name: "approvalInfo",
        query: {
          action: "view",
          id: row.approvalId,
          approvalKey: row.approvalDefKey
        }
      });
    }
  }
};
</script>

<style scoped>
.filter-container {
  margin-bottom: 20px;
  overflow: hidden;
  overflow: hidden;
  display: flex;
  align-items: center;
}
.filter-container-option {
  display: flex;
  flex-wrap: nowrap;
  margin-bottom: 15px;
}
.pagination-container {
  margin-top: 25px;
  overflow: hidden;
  display: flex;
  justify-content: flex-end;
}

.filter-itemBut {
  margin-left: 25px;
}
</style>